<template>
  <div class="bigbox">
    <div class="topbox" :style="{ height: isheight + 'px' }">
      <el-form
        :model="form"
        ref="form"
        :inline="true"
        label-width="90px"
        onsubmit="return false"
      >
        <el-col :span="6">
          <el-form-item label="维护组织">
            <el-select style="width: 100%" v-model="form.orgNo" filterable>
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.bizOrgName"
                :value="item.bizOrgNo"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="电源点名称">
            <el-input v-model="powerPointName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6"> </el-col>
        <el-col :span="6">
          <el-form-item>
            <div>
              <button @click="chongzhi" class="button">重置</button>
              <button @click="submit" class="button chaxun">查询</button>
            </div>
          </el-form-item>
        </el-col>
      </el-form>
    </div>
    <div style="width: 100%; height: 10px; background-color: #f1f1f1"></div>
    <div class="bodybox">
      <div class="titlebox">
        <div class="text">电源点信息</div>
        <div
          class="right"
          :style="{ alignItems: 'center', lineHeight: '32.5px' }"
        >
          <button
            type="primary"
            size="small"
            class="bewdao daochu"
            @click="add"
          >
            新增
          </button>
          <el-tooltip class="item" effect="dark" content="刷新" placement="top">
            <span
              @click="shuaxin"
              :style="{ cursor: 'pointer', fontSize: '20px' }"
              ><i class="el-icon-refresh-right"></i
            ></span>
          </el-tooltip>
          <el-dropdown trigger="click" @command="command">
            <span class="el-dropdown-link">
              <el-tooltip
                class="item"
                effect="dark"
                content="密度"
                placement="top"
              >
                <span :style="{ cursor: 'pointer', fontSize: '20px' }"
                  ><i class="el-icon-d-caret"></i
                ></span>
              </el-tooltip>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item class="dropdown-list" command="默认"
                >默认</el-dropdown-item
              >
              <el-dropdown-item class="dropdown-list" command="中等"
                >中等</el-dropdown-item
              >
              <el-dropdown-item class="dropdown-list" command="紧凑"
                >紧凑</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <div class="table-content">
        <template>
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            border
            id="exportTabyong"
            ref="table"
            :size="iissize"
            :header-cell-style="{
              background: '#f5f5f5',
              'text-align': 'center',
            }"
          >
          <template slot="empty">
              <el-empty description="暂无数据"></el-empty>
            </template>
            <el-table-column
              type="index"
              align="center"
              label="序号"
              width="50"
            >
            </el-table-column>
            <el-table-column prop="orgName" align="center" label="维护组织">
            </el-table-column>
            <el-table-column
              prop="powerPointName"
              align="center"
              label="电源点名称"
            >
            </el-table-column>
            <el-table-column
              prop="powerPointLocation"
              align="center"
              label="地址"
            >
            </el-table-column>
            <el-table-column
              prop="powerPointLongitude"
              label="经度"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="powerPointLatitude"
              align="center"
              label="维度"
            >
            </el-table-column>
            <el-table-column label="操作" width="130">
              <template slot-scope="scope">
                <div class="operate">
                  <i
                    style="
                      font-size: 20px;
                      color: rgb(64, 149, 229);
                      cursor: pointer;
                    "
                    class="el-icon-edit"
                    @click="handleEdit(scope.row)"
                  ></i>
                  <i
                    style="font-size: 20px; color: red; cursor: pointer"
                    class="el-icon-delete"
                    @click="handleDel(scope.row.id)"
                  ></i>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </template>
        <div class="fenye">
          <el-pagination
            background
            layout="prev, pager, next"
            :current-page.sync="pageobj._pageNo"
            @current-change="getdatalist"
            :total="total"
          />
        </div>
      </div>
    </div>
    <div class="dialog">
      <el-dialog
        :title="'电源点信息维护'"
        :visible.sync="centerDialogVisible"
        label-position="left"
        center
        width="800px"
        :destroy-on-close="true"
        :close-on-click-modal="false"
        :before-close="beforeClose"
      >
        <div class="content">
          <Amap
            ref="amap"
            :companyData="companyData"
            v-if="centerDialogVisible"
            @finish="finish"
          />
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import { saveAs } from 'file-saver'
// import {
// // delCustomerFileApi,
// //   getCustomerInfoApi
// // getCustomerInfoApi
// } from '@/api/customerFile'
import Amap from './Amap.vue'
import {
  delPowerPointApi,
  getPowerPointPageApi,
  getTreeListApi
} from '@/api/fileFlow'

export default {
  name: 'ConfigureIndex',
  components: { Amap },
  data () {
    return {
      dataList: [],
      powerPointName: '',
      id: '',
      bizOrgName: '',
      isEdit: false,
      options: [],
      centerDialogVisible: false,
      form: {},
      isshow: false,
      isheight: 72,
      date: [],
      iissize: 'medium',
      props: {
        label: 'bizOrgName'
      },
      isPreview: false,
      // HYFL: [],
      loading: false,
      tableData: [],
      total: 0,
      pageobj: {
        _pageNo: 0,
        _pageSize: 10
      },
      progress: 1,
      addType: '',
      companyData: {}
    }
  },
  created () {
    this.getTreeList()
  },

  async mounted () {
    await this.getdatalist('')
  },

  methods: {
    // 获取维护组织下拉数据
    async getTreeList () {
      const res = await getTreeListApi()
      console.log(res)
      this.options = res.data.list
      this.$set(this.form, 'orgNo', res.data.list[0].bizOrgNo)
    },

    // 获取数据
    async getdatalist (now) {
      this.loading = true
      const res = await getPowerPointPageApi({
        pageNo: this.pageobj._pageNo - 1,
        pageSize: this.pageobj._pageSize,
        orgNo: now,
        powerPointName: this.powerPointName
      })
      this.tableData = res.data.list
      this.total = res.data.totalCount
      console.log(res)
      this.loading = false
    },
    // 刷新列表
    shuaxin () {
      this.getdatalist(this.form.orgNo)
      this.$message.success('列表刷新成功')
    },
    submit () {
      // console.log(this.dataList)
      this.getdatalist(this.form.orgNo)
    },
    command (val) {
      if (val === '默认') {
        this.iissize = 'medium'
      } else if (val === '中等') {
        this.iissize = 'small'
      } else {
        this.iissize = 'mini'
      }
    },
    async chongzhi () {
      this.getTreeList()
      this.getdatalist('')
    },
    // 编辑
    async handleEdit (row) {
      console.log(row)
      //   this.companyData = Object.assign({}, this.companyData)
      this.companyData = { ...row }
      this.isEdit = true
      this.centerDialogVisible = true
    },
    async add () {
      this.isEdit = false
      this.centerDialogVisible = true
    },
    beforeClose () {
      this.centerDialogVisible = false
      this.isEdit = false
      this.companyData = {}
      this.getdatalist('')
    },
    finish () {
      this.centerDialogVisible = false
      this.getdatalist('')
    },
    // 删除
    async handleDel (id) {
      this.$confirm('此操作将永久删除该档案, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          try {
            const res = await delPowerPointApi(id)
            if (res.code === 200) { this.$message.success('删除成功') } else {
              this.$message.error(res.message)
            }
          } catch (err) {
          }
          this.getdatalist(this.form.orgNo)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.option {
  height: auto;
}
.bigbox {
  .topbox {
    background-color: #fff;
    padding: 10px 20px 0 0;
    box-sizing: border-box;
    // height: 80px !important;
    width: 100% !important;
    // transition-property: all;
    // transition-duration: 0.2s;
    ::v-deep .el-form-item {
      width: 100%;
      margin-left: -10px;
    }
    .button {
      width: 63px;
      height: 32px;
      margin-right: 5px;
      background-color: #fff;
      border: 1px solid #ccc;
      border-radius: 3px;
    }
    .chaxun {
      background-color: #1890ff;
      color: #fff;
    }
  }
  .bodybox {
    padding-top: 10px;
    .titlebox {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      .text {
        font-weight: bold;
        font-size: 18px;
      }
      .right {
        align-items: center;
        i {
          margin-left: 10px;
        }
        .bewdao {
          width: 63px;
          height: 32px;
        }
        .daochu {
          background-color: #1890ff;
          color: #fff;
          border: none;
          border-radius: 3px;
        }
      }
    }
    .fenye {
      margin-top: 15px;
      text-align: right;
    }
  }
}
::v-deep .el-form-item__content {
  width: calc(100% - 100px);
}
.bodybox {
  background-color: #fff;
  margin-top: 10px;
  padding: 20px 20px 20px 20px;
}
::v-deep .el-input__inner {
  height: 32px;
}
::v-deep.el-form--inline {
  height: 100% !important;
  box-sizing: border-box;
}
::v-deep .el-input__icon {
  line-height: 20px;
}

.dropdown-list {
  text-align: center;
  width: 50px;
}
.operate {
  display: flex;
  justify-content: space-around;
}
.dialogBtn {
  width: 80px;
  height: 40px;
  border-radius: 4px;
  font-size: 14px;
  text-align: center;
  align-items: center;
}
::v-deep.dialog {
  .el-dialog {
    width: 800px;
    // height: 550px;
    // padding-left: 10px;
    .el-dialog__header {
      padding: 20px 0;
      padding-left: 20px;
      font-size: 14px;
      text-align: left !important;
      border-bottom: 1px solid #f7f7f7;
    }
    // .el-dialog__body {
    //   line-height: 10px;
    //   padding-bottom: 15px;
    // }
    .el-dialog__footer {
      margin-top: 50px;
      height: 60px;
    }
  }
  //   .el-row {
  //     height: 55px;
  //     .el-col {
  //       height: 55px;
  //     }
  //   }
}

::v-deep.el-date-editor {
  .el-range-separator {
    line-height: 22px;
  }
}

::v-deep.dialog-content {
  .el-form-item__error {
    margin-top: -8px;
  }
  .el-form-item {
    height: 50px;
    .el-form-item__content {
      width: 90%;
      .el-select {
        width: 100%;
      }
    }
    .el-form-item__label {
      padding: 0;
      padding-right: 10px;
      padding-top: 3px;
      line-height: 32px;
    }
    margin-bottom: 5px;
  }
}
::v-deep.checkbox-item {
  border-top: 1px solid #f7f7f7;
  border-bottom: 1px solid #f7f7f7;
  margin-top: 20px;
  padding: 20px 0;
  .el-form-item {
    .el-form-item__content {
      width: 750px;
    }
  }
  .el-checkbox-group {
    .el-checkbox {
      margin-right: 0;
    }
  }
  .yewufanwei {
    padding-top: 10px;
  }
}

.map {
  padding: 0px;
  margin: 0px;
  width: 100%;
  height: 500px;
}
button {
  cursor: pointer;
}
.top-line {
  display: flex;
  width: 100%;
  height: 30px;
  padding-bottom: 20px;
  margin-bottom: 30px;
  justify-content: space-between;
  line-height: 30px;
  align-items: center;
  border-bottom: 2px solid #bbb;
  .line {
    width: 12%;
    height: 1px;
    border: 1px solid #e0e0e0;
    background: #bbb;
  }
  .top-item {
    display: flex;
    .circle {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      border: 1px solid #bbb;
      color: #bbb;
      text-align: center;
      line-height: 30px;
      margin-right: 10px;
    }
    .text {
      font-weight: 800;
    }
  }
}
.checked-bgc {
  background-color: #1684fc;
  color: #fff !important;
  border: 1px solid #1684fc !important;
}
</style>
